{% extends "base.html" %}

{% block content %}
<div class="container mt-4">
    <h2>编辑业务层级: {{ node.name }}</h2>
    <div class="card">
        <div class="card-body">
            <form method="POST">
                {{ form.hidden_tag() }}
                <div class="mb-3">
                    {{ form.node_id.label(class="form-label") }}
                    {{ form.node_id(class="form-control", readonly=True) }}
                </div>
                <div class="mb-3">
                    {{ form.parent_id.label(class="form-label") }}
                    {{ form.parent_id(class="form-select") }}
                </div>
                <div class="mb-3">
                    {{ form.level.label(class="form-label") }}
                    {{ form.level(class="form-select") }}
                </div>
                <div class="mb-3">
                    {{ form.code.label(class="form-label") }}
                    {{ form.code(class="form-control") }}
                </div>
                <div class="mb-3">
                    {{ form.name.label(class="form-label") }}
                    {{ form.name(class="form-control") }}
                </div>
                <div class="mb-3">
                    {{ form.version.label(class="form-label") }}
                    {{ form.version(class="form-control") }}
                </div>
                <button type="submit" class="btn btn-primary">更新</button>
                <a href="{{ url_for('hierarchy.index') }}" class="btn btn-secondary">取消</a>
                
                <!-- 删除按钮 -->
                <button type="button" class="btn btn-danger float-end" 
                        data-bs-toggle="modal" data-bs-target="#deleteModal">
                    删除
                </button>
            </form>
        </div>
    </div>
</div>

<!-- 删除确认模态框 -->
<div class="modal fade" id="deleteModal" tabindex="-1">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title">确认删除</h5>
                <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
            </div>
            <div class="modal-body">
                <p>确定要删除业务层级 <strong>{{ node.name }}</strong> 吗？此操作不可恢复！</p>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">取消</button>
                <form action="{{ url_for('hierarchy.delete', node_id=node.node_id) }}" method="POST">
                    <button type="submit" class="btn btn-danger">确认删除</button>
                </form>
            </div>
        </div>
    </div>
</div>
{% endblock %}